<?php

namespace app\admin\model\order;

use think\Model;


class Order extends Model
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'if_rent_text',
        'if_cash_text',
        'order_status_text',
        'payment_code_text',
        'start_time_text',
        'cash_time_text',
        'return_time_text',
        'expire_time_text',
        'if_deferred_text',
        'cash_deferred_text'
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getIfRentList()
    {
        return ['0' => __('If_rent 0'), '1' => __('If_rent 1')];
    }

    public function getIfCashList()
    {
        return ['0' => __('If_cash 0'), '1' => __('If_cash 1')];
    }

    public function getOrderStatusList()
    {
        return ['0' => __('Order_status 0'), '1' => __('Order_status 1'), '2' => __('Order_status 2'), '3' => __('Order_status 3'), '4' => __('Order_status 4'), '5' => __('Order_status 5'), '6' => __('Order_status 6'), '7' => __('Order_status 7')];
    }

    public function getPaymentCodeList()
    {
        return ['0' => __('Payment_code 0'), '1' => __('Payment_code 1'), '2' => __('Payment_code 2')];
    }

    public function getIfDeferredList()
    {
        return ['0' => __('If_deferred 0'), '1' => __('If_deferred 1')];
    }

    public function getCashDeferredList()
    {
        return ['0' => __('Cash_deferred 0'), '1' => __('Cash_deferred 1')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIfRentTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['if_rent']) ? $data['if_rent'] : '');
        $list = $this->getIfRentList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIfCashTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['if_cash']) ? $data['if_cash'] : '');
        $list = $this->getIfCashList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOrderStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPaymentCodeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['payment_code']) ? $data['payment_code'] : '');
        $list = $this->getPaymentCodeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStartTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCashTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cash_time']) ? $data['cash_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getReturnTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['return_time']) ? $data['return_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getExpireTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expire_time']) ? $data['expire_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIfDeferredTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['if_deferred']) ? $data['if_deferred'] : '');
        $list = $this->getIfDeferredList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCashDeferredTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cash_deferred']) ? $data['cash_deferred'] : '');
        $list = $this->getCashDeferredList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setStartTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCashTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setReturnTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setExpireTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
